package com.badibadi.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.badibadi.infos.MyFriendsModel;
import com.badibadi.infos.Results;
import com.badibadi.infos.TempIMGAddressModel;
import com.badibadi.logic.ImgFileListActivity;
import com.badibadi.mail.Mail15_huifuActivity;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.HtmlUtils;
import com.badibadi.mytools.ImageTools;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.ShareSDKTools;
import com.badibadi.mytools.SinaExpressionTools;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.XUtils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.SinaExpressionActivity;
import com.libjph.util.StringUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.view.my_view.MyGridView;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 个人的发动态 ShareSDKTools activity_send_dynamic_name startActivity
 * activity_send_dynamic_send
 * 
 * @author Administrator et_sendDynamic activity_send_dynamic_send onActivity
 *         finish startActivity 1000
 */
@SuppressLint("ValidFragment")
// activity_send_dynamic_send
// sure_upimg_item_img
public class SendDynamicActivity extends BaseActivity implements
		OnClickListener {
	private String TAG = "SendDynamicActivity";
	public int flags = 0;
	public int jurisdiction = 0;// 用于判断选择的什么权限（0所有人/1朋友/2仅自己）
	int p_status = 1;// 上传的时候才会用到，用来和php同步
	// 以下用于点击设置权限后打钩
	public ImageView i_0, i_1, i_2;
	// 点击layout后ImageView打钩
	public LinearLayout ll_0, ll_1, ll_2;
	// @好友
	private static final int AT_FRIENDS = 3;
	public final int ACTIVITY_BIAOQING = 5;
	private ImageView at_friends;
	private ImageView lock;
	private LinearLayout return_btn;
	// private PopupWindow pop;
	// private boolean PopWindowVisible = false;
	public TextView pop_quanxian_setting_allperson,
			pop_quanxian_setting_huiyuan;
	public ImageView head2;

	// 添加图片
	private GridView up_picture_GridView;
	private Item_Adapter_1 adapter;
	private List<TempIMGAddressModel> addressModels_main;
	private List<String> pathStrings;
	com.badibadi.mytools.Dialog dialog;
	// private FragmentManager manager;
	// private SendDynamic_SendFragment sendFragment;

	// private SendDynamic_AtFriends atFriends;
	private TextView location;
	// private AddressCallBack callBack;
	private TextView activity_send_dynamic_name;
	// EditText/
	public EditText et_sendDynamic;
	// 显示EditText的限制数量
	private TextView tv_textNumber;
	// 统计editText数量
	private int textNumber = 0;
	public int limit = 1000;
	/**
	 * uid
	 */
	private String uid;
	/**
	 * 头像
	 */
	private String head;
	/**
	 * 
	 */
	private DisplayImageOptions options;
	private Results results;
	// 如果是空的话就没有定位
	public String Longitude;// 经度
	public String Latitude;// 纬度
	public String address;// 地址
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(SendDynamicActivity.this);
				try {
					Utils.showMessage(SendDynamicActivity.this, getResources()
							.getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 2:
				Utils.ExitPrgress(SendDynamicActivity.this);
				try {
					Utils.showMessage(SendDynamicActivity.this,
							"" + getResources().getString(R.string.l_xb91));
					if (results.isRet()) {
						Intent intent = new Intent(SendDynamicActivity.this,
								AfterLandingActivity.class);
						intent.putExtra("isStartTwoClose", true);
						startActivity(intent);
						SendDynamicActivity.this.finish();
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 3:
				Utils.ExitPrgress(SendDynamicActivity.this);
				Utils.showMessage(SendDynamicActivity.this, getResources()
						.getString(R.string.l_xb92));
				break;
			case 2000:
				// Utils.ExitPrgress(SendDynamicActivity.this);
				Utils.ExitProgress_hen(SendDynamicActivity.this);
				// Utils.ExitPrgress_Noclose(SendDynamicActivity.this);
				Utils.showMessage(SendDynamicActivity.this, getResources()
						.getString(R.string.l_xb18));
				String result = msg.getData().getString("path");
//				Log.v("sss1", "result=" + result);
				pathStrings.add(result);
				addressModels_main.addAll(qiege_content(result, ","));
				adapter.notifyDataSetChanged();
				// System.out.println(result);
//				Log.v("sss1", "上传的路径是:" + result);
				break;
			default:
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.activity_send_dynamic);

		//

		init();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	/**
	 * 切割数据
	 * 
	 * @param con
	 * @param pand
	 * @return
	 */
	private List<TempIMGAddressModel> qiege_content(String con, String pand) {
		String[] ccc = con.split(pand);
		List<TempIMGAddressModel> addressModels = new ArrayList<TempIMGAddressModel>();
		if (ccc.length > 1) {
			for (int i = 0; i < ccc.length; i++) {
				TempIMGAddressModel addressModel = new TempIMGAddressModel();
				addressModel.setImg_address(ccc[i]);
				addressModels.add(addressModel);
			}
		} else {
			TempIMGAddressModel addressModel = new TempIMGAddressModel();
			addressModel.setImg_address(con);
			addressModels.add(addressModel);
		}
		return addressModels;
	}

	public void init() {

		activity_send_dynamic_name = (TextView) this
				.findViewById(R.id.activity_send_dynamic_name);
		activity_send_dynamic_name.setText(""
				+ Utils.getu_Name(SendDynamicActivity.this));
		// 表情按钮
		this.findViewById(R.id.biaoqing).setOnClickListener(this);

		at_friends = (ImageView) this
				.findViewById(R.id.activity_send_dynamic_at_friends);
		pathStrings = new ArrayList<String>();
		at_friends.setOnClickListener(this);
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();
		try {
			uid = Utils.getUid(SendDynamicActivity.this);
			head = Utils.getu_Head(SendDynamicActivity.this);
		} catch (Exception e) {
			// TODO: handle exception
		}
		// uid = "1";

//		Log.v("aaa", "head=" + head);
		head2 = (ImageView) this.findViewById(R.id.senddynamic_head);

		try {
			// // 头像
			ImageLoader.getInstance().displayImage(
					Constants.BadiDownImgUrl + "/" + head
							+ Constants.appPhoto4img, head2, options);
		} catch (Exception e) {
			// TODO: handle exception
		}

		// ImageView at_friends = (ImageView)findViewById(R.id.at_friends);
		// at_friends.setOnClickListener(new View.OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		//
		// }
		// });
		lock = (ImageView) findViewById(R.id.activity_send_dynamic_lock);
		lock.setOnClickListener(SendDynamicActivity.this);
		return_btn = (LinearLayout) this
				.findViewById(R.id.activity_send_dynamic_return_btn);
		return_btn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				SendDynamicActivity.this.finish();
			}
		});
		// atFriends=new SendDynamic_AtFriends();
		// sendFragment = new SendDynamic_SendFragment();
		// manager = getSupportFragmentManager();
		// FragmentTransaction transaction = manager.beginTransaction();
		// transaction.replace(R.id.SendDynamic_layout, sendFragment);
		// transaction.commit();
		addressModels_main = new ArrayList<TempIMGAddressModel>();
		up_picture_GridView = (GridView) findViewById(R.id.up_picture_GridView);
		up_picture_GridView.setVerticalSpacing(5);
		up_picture_GridView.setHorizontalSpacing(5);
		adapter = new Item_Adapter_1(SendDynamicActivity.this);
		up_picture_GridView.setAdapter(adapter);

		// gv.setAdapter(new
		// SendDynamicUpPictureAdapter(SendDynamicActivity.this));

		et_sendDynamic = (EditText) findViewById(R.id.et_sendDynamic);
		// 设置最大为1000个字符
		et_sendDynamic
				.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
						limit) });
		et_sendDynamic.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// TODO Auto-generated method stub
//				Log.v(TAG, "onTextChanged--》s=" + s + "/" + "start=" + start
//						+ "/" + "before=" + before + "/" + "count=" + count);
				// start+count为字的总数
				// 1.字体总数为start+count
				textNumber = start + count;
				if (textNumber == limit) {
					// ShowToast(SendDynamicActivity.this, "不能超过"+limit+"个字符");
					Toast t = Toast.makeText(SendDynamicActivity.this,
							getResources().getString(R.string.l_xb45) + limit,
							0);
					t.setGravity(Gravity.CENTER, 0, 0);
					t.show();
				}
				tv_textNumber.setText("" + (limit - textNumber));
			}

			// 在数据改变前 s是数据改变钱的，start 数据改变前的光标位置 count：0为增加
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
//				Log.v(TAG, "beforeTextChanged s=" + s + "/" + "start=" + start
//						+ "/" + "count=" + count + "/" + "after=" + after);
			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
//				Log.v(TAG, "beforeTextChanged s=" + s);
			}
		});
		tv_textNumber = (TextView) findViewById(R.id.Surplus_textNumber);

		location = (TextView) findViewById(R.id.location);
		LinearLayout dingwei = (LinearLayout) findViewById(R.id.dynamic_dingwei);
		dingwei.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(SendDynamicActivity.this,
						PunchCardActivity.class);
				startActivityForResult(intent, 1);
			}
		});
		this.findViewById(R.id.activity_send_dynamic_send).setOnClickListener(
				this);

		this.findViewById(R.id.fenxiang).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!et_sendDynamic.getText().toString().equals("")) {
							if (et_sendDynamic.getText().toString().length() >= 120) {
								String content = et_sendDynamic.getText()
										.toString().substring(0, 120);

								if (addressModels_main != null
										&& !addressModels_main.isEmpty()) {
									if (!StringUtil
											.isNullOrEmpty(addressModels_main
													.get(0).getImg_address())) {
										ShareSDKTools.ShowOnekeyshare2(
												SendDynamicActivity.this, "",
												"" + content, "",
												Constants.BadiDownImgUrl+"/"+addressModels_main.get(0)
														.getImg_address());
									} else {
										ShareSDKTools.ShowOnekeyshare2(
												SendDynamicActivity.this, "",
												"" + content, "",
												"");
									}

								}

							} else {
								if (addressModels_main != null
										&& !addressModels_main.isEmpty()) {
									if (!StringUtil
											.isNullOrEmpty(addressModels_main
													.get(0).getImg_address())) {
										ShareSDKTools.ShowOnekeyshare2(
												SendDynamicActivity.this, "",
												"" + et_sendDynamic.getText()
												.toString(), "",
												Constants.BadiDownImgUrl+"/"+addressModels_main.get(0)
														.getImg_address());
										
									} else {
										ShareSDKTools.ShowOnekeyshare2(
												SendDynamicActivity.this, "",
												"" + et_sendDynamic.getText()
												.toString(), "",
												"");
									}
								}else
								{
									ShareSDKTools.ShowOnekeyshare2(
											SendDynamicActivity.this, "",
											"" + et_sendDynamic.getText()
											.toString(), "",
											"");
								}
								
								

//                              ShareSDKTools.ShowOnekeyshare2(
//										SendDynamicActivity.this, "", ""
//												+ et_sendDynamic.getText()
//														.toString(), "", "");
							}

						} else {
							Utils.showMessage(SendDynamicActivity.this,
									getResources().getString(R.string.l_xb101));
						}

					}
				});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		// switch (resultCode) {
		// case 2:
		// it.putExtra("Longitude", ""+latLonPoint.getLongitude());
		// it.putExtra("Latitude", ""+latLonPoint.getLatitude());
		// it.putExtra("result", addressName);
		// break;
		// }
		if (requestCode == 1 && resultCode == 2) {
			if (data != null) {
				address = data.getStringExtra("result");
				Longitude = data.getStringExtra("Longitude");
				Latitude = data.getStringExtra("Latitude");
				if (address != null) {
//					Log.v("aaa", "result==>" + address);
					if (location != null)
						location.setText("" + address);
				}
			}
		}

		// 点击表情后回调
		if (requestCode == ACTIVITY_BIAOQING
				&& resultCode == SinaExpressionActivity.ACTIVITY_BIAOQING
				&& flags == 0) {

			if (data != null) {

				String con = data.getExtras().getString("result");
				String con1 = et_sendDynamic.getText().toString();
				String con2 = con1 + con;

				if (con2.length() > limit) {
					Utils.showMessage(this,
							getResources().getString(R.string.l_xb45) + limit);
				} else {
					// et_sendDynamic.setText(con2);
					// et_sendDynamic.setSelection(con2.length());
					String content2 = data.getStringExtra("result");
					int index = et_sendDynamic.getSelectionStart();
					Editable edit = et_sendDynamic.getEditableText();
					edit.insert(index, content2);
				}

				// new HtmlUtils(SendDynamicActivity.this,
				// et_sendDynamic,et_sendDynamic.getText().toString()).showEditText();
			}
		}
		/**
		 * at好友
		 */
		if (requestCode == AT_FRIENDS && resultCode == 3) {
			// et_sendDynamic.setText(et_sendDynamic.getText().toString()+data.getStringExtra("result"));
			List<MyFriendsModel> listObj = (ArrayList<MyFriendsModel>) data
					.getSerializableExtra("result");

			for (int i = 0; i < listObj.size(); i++) {
				if (listObj.get(i).isJudge() == true)
					et_sendDynamic.setText(""
							+ et_sendDynamic.getText().toString() + "@"
							+ listObj.get(i).getNickName() + " ");
			}

//			System.out.println("我是回传数据" + listObj.get(0).getNickName());
		}
		// System.out.println("传出" + requestCode + " " + "回传" + resultCode);
		if (requestCode == 5 && resultCode == 5 && flags == 0) {
//			Log.v(TAG, "SendDynamicActivity onActivityResult");
			ArrayList<String> filelist = data.getStringArrayListExtra("files");
			//
			// if (filelist != null && !filelist.isEmpty()) {
			// for (int i = 0; i < filelist.size(); i++) {
			// TempIMGAddressModel model = new TempIMGAddressModel();
			// model.setImg_address(filelist.get(i));
			// // addressModels.add(model);
			// }
			// }

			// adapter.notifyDataSetChanged();
			// Utils.showPrgress(SendDynamicActivity.this);
			XUtils.UpImg_ceshi_douhaoXUtils(filelist, SendDynamicActivity.this,
					handler);
			// for (int i = 0; i < filelist.size(); i++) {
			// System.out.println("获取到的图片地址是:" + filelist.get(i));
			// }
		}

		super.onActivityResult(requestCode, resultCode, data);
	}

	// private int jurisdiction = 0;// 用于判断选择的什么权限（0所有人/1朋友/2仅自己）
	protected void send() {
//		Log.v(TAG, "SendDynamic");
//		Log.v("sss1", "进入发送接口调用");
//		Utils.showPrgress(SendDynamicActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				try {
					map.put("trends", fengzhuang());
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
//				Log.v(TAG, "发送动态传送的数据是:" + map.toString());
				String content = Utils.sendRequest(map, Constants.BadiUrl
						+ "user_trends");
				
//				Log.v(TAG, "结果是3:" + content);
				if (content != null) {
					results = Utils.checkResult_NNN(SendDynamicActivity.this,
							content);
//					Log.v(TAG, "结果是1:" + results);
					if (results != null && !results.getRetmsg().equals("null")) {
//						Log.v(TAG, "结果是2:" + results.getRetmsg());
						try {
							// Message msg = new Message();
							// msg.what = 2;
							// Bundle bun = new Bundle();
							// bun.putString("retmsg", results.getRetmsg());
							// bun.putBoolean("ret", results.isRet());
							// msg.setData(bun);
							handler.sendEmptyMessage(2);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private JSONObject fengzhuang() throws JSONException {

		//
		// String content = Utils.getRequest(Constants.BadiUrl
		// + "user_trends?uid=" + uid + "&contents=" + contents + "&trends_img="
		// + trends_img + "&p_status="+p_status);
		if (jurisdiction == 2) {
			p_status = 0;
		} else if (jurisdiction == 0) {
			p_status = 1;
		} else if (jurisdiction == 1) {
			p_status = 2;
		}
		final String contents = SinaExpressionTools
				.replaceAllReplaceToPath(et_sendDynamic.getText().toString()
						.trim());
		// Log.v(TAG, "contents==>" + contents);
		String trends_img = "";

		JSONObject object1 = new JSONObject();
		object1.put("uid", uid);
		object1.put("contents", contents);
		object1.put("map_y", Longitude);
		object1.put("map_x", Latitude);
		object1.put("address", address);
//		Log.v(TAG, "object1===>?" + object1.toString());
		if (addressModels_main != null && !addressModels_main.isEmpty()) {
			StringBuffer buffer = new StringBuffer("");
			for (int i = 0; i < addressModels_main.size(); i++) {
				buffer.append(addressModels_main.get(i).getImg_address() + ",");
			}
			String bb = buffer.toString();
			object1.put("trends_img", bb.substring(0, bb.length() - 1));
		} else {
			object1.put("trends_img", "");
		}
		// if (pathStrings != null && !pathStrings.isEmpty()) {
		// for (int i = 0; i < pathStrings.size(); i++) {
		// trends_img += pathStrings.get(i) + ",";
		// }
		// } else {
		// trends_img = "";
		// }
		// if (!trends_img.equals("")) {
		// object1.put("trends_img",
		// trends_img.substring(0, trends_img.length() - 1));
		// } else {
		// object1.put("trends_img", "");
		// }

		object1.put("p_status", "" + p_status);
		return object1;
	}

	/**
	 * 用于更新popWindow中的三个选项，根据jurisdiction值
	 * 
	 * @param Click
	 *            (点击的是哪个layout)
	 */
	public void setJurisdictionOnClickListener(int Click) {
		switch (Click) {
		case 0:
			if (jurisdiction != 0)
				jurisdiction = 0;
			i_0.setVisibility(View.VISIBLE);
			i_1.setVisibility(View.GONE);
			i_2.setVisibility(View.GONE);
			break;
		case 1:
			if (jurisdiction != 1)
				jurisdiction = 1;
			i_0.setVisibility(View.GONE);
			i_1.setVisibility(View.VISIBLE);
			i_2.setVisibility(View.GONE);
			break;
		case 2:
			if (jurisdiction != 2)
				jurisdiction = 2;
			i_0.setVisibility(View.GONE);
			i_1.setVisibility(View.GONE);
			i_2.setVisibility(View.VISIBLE);
			break;
		}
	}

	private void settingPopWindows(int i) {
		// TODO Auto-generated method stub
		switch (i) {
		case 3:
			setPopWindowsVisible();
			break;
		}
	}

	/**
	 * 是否可见,在这里面设置popwindow的点击事件
	 * 
	 * @param visible
	 */
	public void setPopWindowsVisible() {
		dialog = new com.badibadi.mytools.Dialog();
		// if (PopWindowVisible != true) {
		// PopWindowVisible = true;
		LayoutInflater inflater = LayoutInflater.from(SendDynamicActivity.this);
		View root = inflater.inflate(R.layout.pop_quanxian_setting, null);
		// 下面的是相册权限的
		i_0 = (ImageView) root.findViewById(R.id.cnewpoly_quanxian_01);
		ll_0 = (LinearLayout) root.findViewById(R.id.create_new_poly_layout01);
		i_1 = (ImageView) root.findViewById(R.id.cnewpoly_quanxian_02);
		ll_1 = (LinearLayout) root.findViewById(R.id.create_new_poly_layout02);
		i_2 = (ImageView) root.findViewById(R.id.cnewpoly_quanxian_03);
		ll_2 = (LinearLayout) root.findViewById(R.id.create_new_poly_layout03);
		pop_quanxian_setting_allperson = (TextView) root
				.findViewById(R.id.pop_quanxian_setting_allperson);
		pop_quanxian_setting_huiyuan = (TextView) root
				.findViewById(R.id.pop_quanxian_setting_huiyuan);
		ll_0.setOnClickListener(SendDynamicActivity.this);
		ll_1.setOnClickListener(SendDynamicActivity.this);
		ll_2.setOnClickListener(SendDynamicActivity.this);
		setJurisdictionOnClickListener(jurisdiction);

		Button finish = (Button) root.findViewById(R.id.finish);
		finish.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialog.DialogDissMiss();
			}
		});
		// LinearLayout quanxianshezhi = (LinearLayout) root
		// .findViewById(R.id.quanxianshezhi);
		//
		// int w = View.MeasureSpec.makeMeasureSpec(0,
		// View.MeasureSpec.UNSPECIFIED);
		// int h = View.MeasureSpec.makeMeasureSpec(0,
		// View.MeasureSpec.UNSPECIFIED);
		// quanxianshezhi.measure(w, h);
		// final int height = quanxianshezhi.getMeasuredHeight();
		// int width = quanxianshezhi.getMeasuredWidth();
		// Log.v("aaa", "height===>" + height + "width====>" + width);
		// // 下面四个属性可以让popwindow点击屏幕其他地方关闭
		// pop.setBackgroundDrawable(new BitmapDrawable());
		// pop.setFocusable(true);
		// pop.setTouchable(true);
		// pop.setOutsideTouchable(true);
		// pop.showAtLocation(findViewById(R.id.SendDynamic_layout),
		// Gravity.CENTER, 500, height);
		// } else if (PopWindowVisible != false) {
		// PopWindowVisible = true;
		// pop.dismiss();
		// }

		dialog.CreateDialog(SendDynamicActivity.this, root);
	}

	// /** At朋友*/
	// class SendDynamic_AtFriends extends Fragment{
	//
	// @Override
	// public View onCreateView(LayoutInflater inflater, ViewGroup container,
	// Bundle savedInstanceState) {
	// // TODO Auto-generated method stub
	// View view=inflater.inflate(R.layout.fragment_senddynamic_at_friends,
	// null);
	//
	// return view;
	// }
	// }
	private class Item_Adapter_1 extends BaseAdapter {
		private Context context;

		public Item_Adapter_1(Context context) {
			this.context = context;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return addressModels_main.size() + 1;
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return addressModels_main.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(final int arg0, View convertView, ViewGroup arg2) {
			if (arg0 < addressModels_main.size()) {
				// if (convertView == null) {
				// convertView = ViewHolder.buildView(context,
				// R.layout.sure_upimg_item_main, arg2);
				// }
				// ViewHolder viewHolder = (ViewHolder) convertView.getTag();
				LayoutInflater viewHolder = LayoutInflater.from(context);
				convertView = viewHolder.inflate(R.layout.sure_upimg_item_main,
						null);
				ImageView sure_upimg_item_img = (ImageView) convertView
						.findViewById(R.id.sure_upimg_item_img);

				// pathtobitmap(addressModels_main.get(arg0).getImg_address(),
				// sure_upimg_item_img);
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl
								+ addressModels_main.get(arg0).getImg_address()
								+ Constants.App9block, sure_upimg_item_img,
						options);

				sure_upimg_item_img
						.setOnLongClickListener(new OnLongClickListener() {
							@Override
							public boolean onLongClick(View arg10) {
								new AlertDialog.Builder(context)
										.setTitle(
												getResources().getString(
														R.string.l_xb140))
										.setIcon(R.drawable.icon)
										.setMessage(
												getResources().getString(
														R.string.l_xb141))
										.setPositiveButton(
												getResources().getString(
														R.string.Yes),
												new DialogInterface.OnClickListener() {

													@Override
													public void onClick(
															DialogInterface arg20,
															int arg1) {
														// addressModels_main.get(arg0).getImg_address();
														addressModels_main
																.remove(arg0);
														Notific();
													}
												})
										.setNegativeButton(
												getResources().getString(
														R.string.No),
												new DialogInterface.OnClickListener() {

													@Override
													public void onClick(
															DialogInterface arg0,
															int arg1) {

													}
												}).show();
								return false;
							}
						});
			}

			if (addressModels_main.isEmpty()
					|| arg0 >= addressModels_main.size()) {
				// System.out.println("运行2：" + arg0 + " " +
				// imgAddressModels.size());
				// if (convertView == null) {
				// convertView = ViewHolder.buildView(context,
				// R.layout.sure_upimg_main, arg2);
				// }
				// ViewHolder viewHolder = (ViewHolder) convertView.getTag();
				LayoutInflater viewHolder = LayoutInflater.from(context);
				convertView = viewHolder
						.inflate(R.layout.sure_upimg_main, null);
				ImageView sure_upimg_item_img_add = (ImageView) convertView
						.findViewById(R.id.sure_upimg_item_img_add);
				sure_upimg_item_img_add
						.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub
								Intent intent = new Intent(
										SendDynamicActivity.this,
										ImgFileListActivity.class);
								intent.putExtra("panduan", "no_set");
								// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
								startActivityForResult(intent, 5);
								// context.startActivity(intent);
							}
						});
			}
			return convertView;
		}

		private void pathtobitmap(String p, ImageView im) {
			im.setImageBitmap(com.badibadi.mytools.ImageLoader
					.decodeSampledBitmapFromResource(p, 60));
		}

		public void Notific() {
			Item_Adapter_1.this.notifyDataSetChanged();
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.create_new_poly_layout01:
			setJurisdictionOnClickListener(0);
			break;
		case R.id.create_new_poly_layout02:
			setJurisdictionOnClickListener(1);
			break;
		case R.id.create_new_poly_layout03:
			setJurisdictionOnClickListener(2);
			break;
		case R.id.activity_send_dynamic_lock:
			settingPopWindows(3);
			break;
		case R.id.activity_send_dynamic_send:
			// 相应了
//			Log.v("sss1", "发送点击成功");
			if (et_sendDynamic.getText().toString().equals("")) {
				Utils.showMessage(SendDynamicActivity.this, getResources()
						.getString(R.string.l_xb142));
			} else {
				send();
			}

			break;
		case R.id.activity_send_dynamic_at_friends:
			Intent intent = new Intent(SendDynamicActivity.this,
					MyFriendsResultActivity.class);
			startActivityForResult(intent, AT_FRIENDS);
			break;
		case R.id.biaoqing:
			Intent intent2 = new Intent(SendDynamicActivity.this,
					SinaExpressionActivity.class);
			startActivityForResult(intent2, ACTIVITY_BIAOQING);
			break;
		}
	}
}
